/*
 *  Copyright 2010 asustatil.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package edu.upf.userinterface.impl;

import edu.upf.utils.LogSystem;
import java.awt.*;
import javax.swing.*;

public class SplashScreen extends JWindow {

    public SplashScreen(int time) {
        LogSystem log = new LogSystem(this.getClass());
        ImageIcon ii = new ImageIcon(getClass().getResource("/jMedia_logo.png"));
        JScrollPane jsp = new JScrollPane(new JLabel(ii));
        getContentPane().add(jsp);
        setSize(ii.getIconWidth()+20, ii.getIconHeight()+20);
        centerScreen();
        setVisible(true);
        if (time != 0) {
            try {
                Thread.sleep(time);
                dispose();
            } catch (InterruptedException ie) {
                log.addInfoLog("Splash screen interrupted");
            }
        }
    }

    private void centerScreen() {
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (int) ((d.getWidth() - getWidth()) / 2);
        int y = (int) ((d.getHeight() - getHeight()) / 2);
        setLocation(x, y);
    }
}
